package com.gitee.neuray.security.common.biz;

import com.gitee.neuray.security.common.entity.MultBaseEntity;
import com.gitee.neuray.security.common.exception.BaseException;
import com.gitee.neuray.security.common.mapper.MultBaseMapper;
import com.gitee.neuray.security.common.util.UUIDUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;

/**
 * @author: zhhongyu
 * @description:
 * @since: Create in 12:21 2020/3/22
 */
public abstract class MultBaseBiz<M extends MultBaseMapper> {
    @Autowired
    protected M mapper;

    public <T extends MultBaseEntity> void insert(T entity){
        entity.setId(UUIDUtils.generateShortUuid());
        mapper.insertCustom(entity);
    }
    public <T extends MultBaseEntity> void update(T entity){
        if(StringUtils.isEmpty(entity)){
            throw new BaseException("主键不能为空...");
        }
        mapper.updateCustom(entity);
    }

    public void deleteById (String id){
        mapper.deleteById(id);
    }
}
